package cn.sdormitory.controller.evaluation;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.common.utils.SysUserUtils;
import cn.sdormitory.evaluation.entity.WorkDayEntity;
import cn.sdormitory.evaluation.entity.WorkStuCheckEntity;
import cn.sdormitory.evaluation.service.WorkDayService;
import cn.sdormitory.evaluation.vo.WorkDayVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "班主任每日任务")
@RequestMapping("/workday")
public class WorkDayController {

    @Resource
    WorkDayService workDayService;

    /**
     * 查询任务列表
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/pageList")
    public CommonResult<CommonPage> addjob(@RequestBody WorkDayVO vo) throws Exception {
        WorkDayEntity entity = new WorkDayEntity();
        BeanUtils.copyProperties(vo,entity);
        IPage<WorkDayEntity> workDayPageList = workDayService.findWorkDayPageList(entity);
        return CommonResult.success(CommonPage.restPage(workDayPageList));
    }

    /**
     * 查询学生情况
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/studentByType")
    public CommonResult<List<WorkStuCheckEntity>> studentListByType(@RequestBody WorkStuCheckEntity vo) throws Exception {
        List<WorkStuCheckEntity> workStuCheckEntities = workDayService.studentListByType(vo);
        return CommonResult.success(workStuCheckEntities);
    }

    /**
     * 查询学生情况
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/getDetailById")
    public CommonResult<WorkDayEntity> getDetailById(@RequestBody WorkDayEntity vo) throws Exception {
        WorkDayEntity workDayEntity = workDayService.getDetailById(vo.getId());
        return CommonResult.success(workDayEntity);
    }

    /**
     * 修改
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/updateDetailById")
    public CommonResult<WorkDayEntity> updateDetailById(@RequestBody WorkDayEntity vo) throws Exception {
        int i = workDayService.updateDetailById(vo);
        if(i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 添加检查结果
     * @param vo
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/addCheckResult")
    public CommonResult<WorkDayEntity> addCheckResult(@RequestBody List<WorkStuCheckEntity> vo) throws Exception {
        int i = workDayService.addCheckResult(vo);
        if(i>0){
            return CommonResult.success();
        }
        return CommonResult.failed();
    }







}
